package com.mapper;

import com.pojo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {

    @Select("select * from teacher where account = #{account}")
    Teacher getByAccount(String account);

    @Select("select * from teacher limit #{page},#{pagesize}")
    List<Teacher> getList(Integer page,Integer pagesize);

    @Select("select count(*) from teacher")
    Integer countTeacher();

    @Select("select * from station where name = #{name}")
    Station getStationByName(String name);

    @Select("select * from station where id = #{id}")
    Station getStationById(Integer id);

    @Insert("insert into station(name) value(#{name})")
    void addStation(String name);

    @Delete("delete from station where id = #{id}")
    void delStation(Integer id);

    @Update("update station set name = #{name} where id = #{id}")
    void editStation(Integer id,String name);

    @Select("select * from station")
    List<Station> getStations();

    @Select("select * from teacher where jobnum = #{jobnum}")
    Teacher getByJobnum(String jobnum);

    @Insert("insert into teacher(station_id,gender,jobnum,name,account,password,introduce,avatar) " +
            "value(#{station_id},#{gender},#{jobnum},#{name},#{account},#{password},#{introduce},#{avatar})")
    void addTeacher(Integer station_id,Integer gender,String jobnum,String name,String account,String password,String introduce,String avatar);

    @Select("select * from teacher where id = #{id}")
    Teacher getById(Integer id);

    @Delete("delete from teacher where id = #{id}")
    void delTeacher(Integer id);

    @Update("update teacher set avatar = #{avatar} where id = #{id}")
    void editAvatar(Integer id,String avatar);

    @Update("update teacher set introduce = #{introduce} where id = #{id}")
    void editIntroduce(Integer id,String introduce);

    @Update("update teacher set password = #{password} where id = #{id}")
    void editPassword(Integer id,String password);

    @Select("select * from team where topic_id in (select id from topic where teacher_id = #{teacher_id} and state = 2) and topic_state = 0 limit #{page},#{pagesize}")
    List<Team> getSubscribe(Integer teacher_id,Integer page,Integer pagesize);

    @Select("select count(*) from team where topic_id in (select id from topic where teacher_id = #{teacher_id} and state = 2) and topic_state = 0")
    Integer countSubscribe(Integer teacher_id);

    @Select("select * from topic where id = #{topic_id}")
    Topic getTopicById(Integer topic_id);

    @Select("select * from student where team_id = #{team_id} and open_id != #{open_id}")
    List<Student> getTeamById(Integer team_id,String open_id);

    @Select("select topic_state from team where id = #{team_id}")
    Integer getTopicState(Integer team_id);

    @Update("update team set topic_state = #{state} where id = #{team_id}")
    void toExamine(Integer team_id,Integer state);

    @Update("update student set teacher_id = #{teacher_id} where team_id = #{team_id}")
    void updateStudentTeacher(Integer team_id,Integer teacher_id);

    @Select("select * from student where open_id = #{id}")
    Student getStudentById(String Id);

}
